﻿using System;
using System.Linq;

namespace WebService_Newstore.DAO
{
    public class ArticleDAO: BaseDAO
    {
        public int idMySql{ get; set; }
        public int idOracle { get; set; }
        public string reference { get; set; }
        public int idUniteReference { get; set; }          //unité de référence de l'article

        /// <summary>
        /// chargement de l'objet article correspondant à la table de la BDD
        /// </summary>
        /// <param name="idArt">idArt, l'identifiant de l'article</param>
        public ArticleDAO(int idArt)
        {
            using (newStoreContext = new newStoreEntities())
            {
                try
                {
                    var query = from article in newStoreContext.articles
                                where article.id_article == idArt
                                select article;

                    if (query.LongCount() == 0)
                        throw new Exception("Aucun article avec cet id !!");

                    foreach (var art in query)
                    {
                        Console.WriteLine(art.id_article + " " + art.id_article_oracle);

                        //On instancie l'article DAO
                        this.idMySql = art.id_article;
                        this.idOracle = art.id_article_oracle;
                        this.idUniteReference = art.id_unite;
                        this.reference = art.ref_article;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }

        }

        /* Pas bon
        public void UpdateArticle(int idArt,int idArtOracle,string refArt,int idUnite)
        {
             WebService_Newstore.article.Createarticle(idArt,idArtOracle,refArt,idUnite);
        }*/

    }
}